package cc.idoone.spring_boot_hello.web.filter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * <h3>WebFilter 测试</h3>
 * <p>
 * 需要在启动入口处添加一个核心的注解@ServletComponentScan
 * </p>
 * <p>
 * 方式二：定义Bean: FilterRegistrationBean(参考 ApplicationConfiguration)
 * </p>
 *
 * @author hemj
 * @version 2017/9/22
 */
@WebFilter(filterName = "HelloFilter", urlPatterns = "/*")
public class HelloFilter implements Filter {

	public void destroy() {
		System.out.println("HelloFilter destroy");
	}

	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
		System.out.println("HelloFilter doFilter");
		chain.doFilter(req, resp);
	}

	public void init(FilterConfig config) throws ServletException {
		System.out.println("HelloFilter init");
	}

}
